package ${jpad.packageName}.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wing.common.util.GUID;
import com.wing.common.util.PageBean;
import ${jpad.packageName}.dao.${jpad.domainName}Dao;
import ${jpad.packageName}.domain.${jpad.domainName};
/**
 * 
 * @author please write yout name
 * 
 */
@Service
@Transactional
public class ${jpad.domainName}Manager {
	@Autowired
	private ${jpad.domainName}Dao ${jpad.domainName?lower_case}dao;
	
	
	/**
	 * 获得该对象所有数据的列表
	 * 
	 * @return list
	 */
	public List<Map<String,Object>> findAll(){
		return ${jpad.domainName?lower_case}dao.findAll();	 
	}
	
	public PageBean findPageList(int currentPage, int pageSize){
		return ${jpad.domainName?lower_case}dao.findPageList(currentPage,pageSize);	 
	}
	
	/**
	 * 通过id得到对象
	 *
	 * @param  id
	 * @return pObject
	 */
	public ${jpad.domainName} findById(String id){
		return ${jpad.domainName?lower_case}dao.findById(id);	 
	}
	
	/**
	 * 保存对象
	 *
	 * @param  ${jpad.domainName?lower_case}
	 */
	public void save${jpad.domainName}(${jpad.domainName} ${jpad.domainName?lower_case}){
		if(${jpad.domainName?lower_case}.getId() == null ||  "".equals(${jpad.domainName?lower_case}.getId())){
			${jpad.domainName?lower_case}.setId(new GUID().toString());
			${jpad.domainName?lower_case}dao.insert(${jpad.domainName?lower_case});
		}else{
			${jpad.domainName?lower_case}dao.update(${jpad.domainName?lower_case});
		}
	}

	/**
	 * 编辑对象
	 *
	 * @param  ${jpad.domainName?lower_case}
	 */
	public void update${jpad.domainName}(${jpad.domainName} ${jpad.domainName?lower_case}){
		${jpad.domainName?lower_case}dao.update(${jpad.domainName?lower_case});
	}
	
	 /**
	 * 删除对象
	 *
	 * @param  chk 对象id数组
	 */
	public void delete${jpad.domainName}s(String[] chk) {
		for(int i=0;i<chk.length;i++){
			${jpad.domainName?lower_case}dao.delete(chk[i]);
		}
	}
}


